<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>

<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>用户展示页面</title>
    <link href="./css/bootstrap.min.css" rel="stylesheet">
    <script src="./js/jquery-3.2.1.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>

    <script>
        $(function () {
            let cks = $(".cks");
           $("#ck").click(function () {
               for (let i = 0;i<cks.length;i++){
                   cks[i].checked = this.checked ;
               }
           });
            //获取复选框的value值

            $("#btn").click(function () {
                if (confirm("您确定要删除吗")) {
                let arr = new Array();
                for (let i = 0;i<cks.length;i++){
                    if ( cks[i].checked) {
                        arr.push(cks[i].value);
                    }
                }
                location.href="${pageContext.request.contextPath}/user?method=deleteByIds&ids="+ arr;
                }
            });


        });
    </script>
</head>

<body>
<div align="center">
    <button class="btn btn-success btn-lg"
            onclick='location.href="pages/User_Add.jsp"'>新增用户
    </button>
</div>
<div align="left">
    <table class="table table-striped">
        <thead>
        <tr>
            <th>
                <input type="checkbox" id="ck">
            </th>
            <th>用户Id</th>
            <th>用户名称</th>
            <th>用户邮箱地址</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${userList}" var="user" varStatus="s">
            <tr>
                <th>
                    <input type="checkbox" class="cks" value="${user.id}"/>
                </th>
                <th>${user.id}</th>
                <th>${user.username}</th>
                <th>${user.email}</th>
                <th>
                    <button type="button" class="btn" onclick='location.href="${pageContext.request.contextPath}/user?method=findById&uid=${user.id}"'>修改
                    </button>
                    <button type="button" class="btn" onclick='location.href="${pageContext.request.contextPath}/user?method=delete&uid=${user.id}"'>删除
                    </button>
                </th>
            </tr>
        </c:forEach>

            <tr>
                <th>
                    <button type="button" class="btn" id="btn" >批量删除
                    </button>
                </th>
            </tr>
        </tbody>
    </table>
</div>
</body>
</html>
